package org.albino.evinreisi.service;

import javax.annotation.PostConstruct;
import javax.inject.Named;

import org.albino.evinreisi.authentication.AuthenticationToken;
import org.albino.evinreisi.beans.User;
import org.springframework.context.annotation.Scope;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.context.SecurityContextHolder;


@Named("userService")
@Scope("session")
public class UserService {

	private User user;

	@PostConstruct
	public void initUserService(){
		System.out.println("@PostConstruct ");
		user = new User();
		
		AuthenticationToken authenticationToken =  (AuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
		if(authenticationToken!=null){
			user.setUserName(authenticationToken.getName());
			user.setPassword(authenticationToken.getPassword());
//			user.setAuthenticationTokenId(authenticationToken.getAuthenticationWebServiceResponse().getAuthenticationTokenId());
//			UserPhoneBookQueryAccountWebServiceResponse userPhoneBookQueryAccountWebServiceResponse = prepareUserPhoneBookQueryAccountWebServiceResponse(user);
//			
//			if(userPhoneBookQueryAccountWebServiceResponse.getWebServiceResponseType().equals(WebServiceResponseType.SUCCESS)){
//				user.setUserPhoneBookQueryAccountList(userPhoneBookQueryAccountWebServiceResponse.getUserPhoneBookQueryAccountList());
//				
//			}else{
//				System.out.println("userPhoneBookQueryAccountWebServiceResponse FAILED");
//			}
//			
		}else {
			throw new BadCredentialsException("AuthenticationToken NULL");
		}
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	
	
}
